package com.szq.yygh.hosp.controller.api;

import com.szq.yygh.common.result.Result;
import com.szq.yygh.hosp.service.DepartmentService;
import com.szq.yygh.hosp.vo.hosp.DepartmentQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/***
 * All rights Reserved, Designed By www.jx-lab.com
 * @Title: DepartmentController
 * @Description:
 * @author lixy
 * @date 2021/8/19 17:36
 * @version V1.0
 * @Copyright: www.jx-lab.com Inc. All rights reserved.
 * 注意：本内容仅限于众合景轩信息技术有限公司内部传阅，禁止外泄以及用于其他的商业目
 */
@Api("科室管理")
@RestController
@RequestMapping("/api/hosp")
public class DepartmentApiController extends BaseController {

    @Autowired
    private DepartmentService departmentService;

    @ApiOperation("上传科室信息")
    @PostMapping("/saveDepartment")
    public Result saveDepartment(HttpServletRequest request){
        Map<String, Object> requestMap = getRequestMap(request);
        departmentService.saveDepartment(requestMap);
        return Result.ok();
    }

    @ApiOperation("查询科室列表")
    @PostMapping("/department/list")
    public Result listDepartment(HttpServletRequest request){
        Map<String, Object> requestMap = getRequestMap(request);
        Integer page = StringUtils.isEmpty(requestMap.get("page"))
                ? 1: Integer.parseInt(requestMap.get("page").toString());
        Integer limit = StringUtils.isEmpty(requestMap.get("limit"))
                ? 10: Integer.parseInt(requestMap.get("limit").toString());
        String hoscode = (String) requestMap.get("hoscode");
        DepartmentQueryVo departmentQueryVo = new DepartmentQueryVo();
        if (!StringUtils.isEmpty(hoscode)){
            departmentQueryVo.setHoscode(hoscode);
        }
        return Result.ok(departmentService.selectPage(page, limit, departmentQueryVo));
    }

    @ApiOperation("删除科室信息")
    @PostMapping("/department/remove")
    public Result removeDepartment(HttpServletRequest request){
        Map<String, Object> requestMap = getRequestMap(request);
        String hoscode = (String) requestMap.get("hoscode");
        String depcode = (String) requestMap.get("depcode");
        departmentService.removeDepartment(hoscode, depcode);
        return Result.ok();
    }
}
